//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

// TODO: Remove code that display help...

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{

    // *********************************************************************
    //  MyForumsView
    //
    /// <summary>
    /// This server control is used to display top level threads. Note, a thread
    /// is a post with more information. The Thread class inherits from the Post
    /// class.
    /// </summary>
    /// 
    // ********************************************************************/
//    public class MyForumsView : SkinnedWebControl 
//    {
//
//        #region Member variables and constructor
//        string skinFilename              = "View-MyForums.ascx";
//        
//        CSContext csContext = CSContext.Current;
//        //internal Forum forum;
//        //Control threadDisplay;
//        Control noThreadsToDisplay;
//        internal Repeater announcements;
//        internal Repeater threads;
//        ForumPager pager;
//        CurrentPage currentPage;
//        ThreadSet threadSet;
//        DateFilter dateFilter;
//        SortThreadsBy sortBy = SortThreadsBy.LastPost;
//        SortOrder sortOrder = SortOrder.Ascending;
//        ThreadViewMode mode = ThreadViewMode.Default;
//        //EmailNotificationDropDownList ddlTracking;
//        ThreadSortDropDownList threadSortddl;
//        SortOrderDropDownList sortOrderddl;
//        Button sortButton;
//        Button rememberSettingsButton;
//        HideReadPostsDropDownList hideReadPosts;
//		
//
//        // *********************************************************************
//        //  MyForumsView
//        //
//        /// <summary>
//        /// The constructor simply checks for a ForumID value passed in via the
//        /// HTTP POST or GET.
//        /// properties.
//        /// </summary>
//        /// 
//        // ********************************************************************/
//        public MyForumsView() 
//        {
//
//            if (SkinFilename == null)
//                SkinFilename = skinFilename;
//
//        }
//        #endregion
//
//        #region Skin initialization
//        // *********************************************************************
//        //  Initializeskin
//        //
//        /// <summary>
//        /// Initializes the user control loaded in CreateChildControls. Initialization
//        /// consists of finding well known control names and wiring up any necessary events.
//        /// </summary>
//        /// 
//        // ********************************************************************/ 
//        protected override void InitializeSkin(Control skin) 
//        {
//
//            // Find the controls we need to databind
//            //
//            //threadDisplay = skin.FindControl("ThreadDisplay");
//            noThreadsToDisplay = skin.FindControl("NoThreadsToDisplay");
//            threads = (Repeater) skin.FindControl("Threads");
//            announcements = (Repeater) skin.FindControl("Announcements");
//            hideReadPosts = (HideReadPostsDropDownList) skin.FindControl("HideReadPosts");
//            threadSortddl = (ThreadSortDropDownList) skin.FindControl("SortThreads");
//            sortOrderddl = (SortOrderDropDownList) skin.FindControl("SortOrder");
//
//            // Ensure we have an authenticated user if the user is asking for the private messages
//            //
//            if ((csContext.SectionID == 0) && (csContext.User.IsAnonymous))
//                throw new CSException(CSExceptionType.SectionNotFound, csContext.SectionID.ToString());
//
//            sortButton = (Button) skin.FindControl("SortThreadsButton");
//            if (sortButton != null) 
//            {
//                sortButton.Text = ResourceManager.GetString("ViewThreads_SortThreads");
//                sortButton.Click += new EventHandler(Sort_Changed);
//            }
//
//
//            rememberSettingsButton = (Button) skin.FindControl("RememberSettingsButton");
//            if (rememberSettingsButton != null) 
//            {
//                rememberSettingsButton.Text = ResourceManager.GetString("ViewThreads_RememberSettings");
//                rememberSettingsButton.Click += new EventHandler(RememberSortSettings_Click);
//            }
//
//            // Subscribe to the date filter's changed event
//            //
//            dateFilter = (DateFilter) skin.FindControl("DateFilter");
//
//            if (dateFilter != null)
//                dateFilter.DateChanged += new EventHandler(Sort_Changed);
//            else
//                dateFilter = new DateFilter();
//
//            // Find the Pager and current page controls
//            //
//            pager = (ForumPager) skin.FindControl("Pager");
//            currentPage = (CurrentPage) skin.FindControl("CurrentPage");
//
//            // Do we have any sortBy / sortOrder data?
//            //
//            SetSort();
//
//            // Do we have any rembered settings to apply?
//            if (!csContext.User.IsAnonymous) 
//            {
//                UserCookie cookie = new UserCookie(csContext.User);
//
//                ForumUserOptions options = cookie.GetForumOptions(csContext.SectionID);
//
//                if (options.HasSettings) 
//                {
//                    
//                    dateFilter.Items.FindByValue( ((int) options.DateFilter).ToString() ).Selected = true;
//                    hideReadPosts.SelectedValue = options.HideReadPosts;
//                    threadSortddl.SelectedValue = options.SortBy;
//                    sortOrderddl.SelectedValue = options.SortOrder;
//
//                }
//
//            } 
//            else if (mode != ThreadViewMode.Default) 
//            {
////                if (!csContext.User.IsAnonymous)
////                    ddlTracking.Visible = false;
//            }
//
//            if (csContext.User.IsAnonymous) 
//            {
//                hideReadPosts.Visible = false;
//                rememberSettingsButton.Visible = false;
//                dateFilter.Items.FindByValue( ((int) CSContext.Current.SiteSettings.DefaultThreadDateFilter).ToString() );
//            }
//
//            DataBind();
//
//
//        }
//        #endregion
//
//        #region Internal helper methods
//        private void SetSort() 
//        {
//
//			CSContext context = CSContext.Current;
//
//            int _sortBy = context.GetIntFromQueryString("sb",-1);
//            int _sortOrder = context.GetIntFromQueryString("d",-1);
//
//            if (_sortBy > -1)
//                sortBy = (SortThreadsBy) _sortBy;
//
//            if (_sortOrder > -1)
//                sortOrder = (SortOrder) _sortOrder;
//
//        }
//        #endregion
//
//        #region Events
//        public void Sort_Changed (Object sender, EventArgs e) 
//        {
//            DataBind();
//        }
//
//        public void RememberSortSettings_Click (Object sender, EventArgs e) 
//        {
//            string forumSettings = (int) threadSortddl.SelectedValue + ":" + (int) sortOrderddl.SelectedValue + ":" + (int) dateFilter.SelectedValue + ":" + hideReadPosts.SelectedValue.ToString().Substring(0,1) + ":" + (int) ThreadUsersFilter.HideTopicsParticipatedIn;
//            UserCookie userCookie = new UserCookie( csContext.User );
//            userCookie.SaveForumOptions(csContext.SectionID, forumSettings);
//            Sort_Changed(sender, e);
//        }
//
//        #endregion
//
//        #region Databinding
//        public override void DataBind() 
//        {
//            DateTime dateFilterValue;
//            int forumID = -1;
//
////            if ((forum != null) && (forum.SectionID > 0))
////                forumID = forum.SectionID;
//
//            if (dateFilter.SelectedValue == ThreadDateFilterMode.LastVisit)
//                dateFilterValue = CSContext.Current.User.GetUserCookie().LastVisit;
//            else
//                dateFilterValue = dateFilter.SelectedDate;
//
//
//            // Get a populated thread set
//            //
//            ForumThreadQuery query = new ForumThreadQuery();
//            query.ForumID = forumID;
//            query.PageIndex = pager.PageIndex;
//            query.PageSize = pager.PageSize;
//            query.ThreadsNewerThan = dateFilterValue;
//            query.SortBy = threadSortddl.SelectedValue;
//            query.Order = sortOrderddl.SelectedValue;
//            query.UserFilter = ThreadUsersFilter.HideTopicsParticipatedIn;
//            query.UnReadOnly = hideReadPosts.SelectedValue;
//
//            threadSet = Threads.GetThreads(query);
//
//            if ((threadSet.Announcements.Count > 0) && (mode != ThreadViewMode.Unanswered) && (mode != ThreadViewMode.Active) ) 
//            {
//                announcements.DataSource = threadSet.Announcements;
//                announcements.DataBind();
//            } 
//            else if ( (mode != ThreadViewMode.Unanswered) && (mode != ThreadViewMode.Active) )  
//            {
//                announcements.DataSource = null;
//                announcements.DataBind();
//            }
//
//            // Do we have posts to display?
//            //
//            if (threadSet.Threads.Count > 0) 
//            {
//                threads.DataSource = threadSet.Threads;
//                threads.DataBind();
//            } 
//            else 
//            {
//                threads.DataSource = null;
//                threads.DataBind();
//            }
//
//            // Do we have announcements or threads?
//            //
//            if ((threads.DataSource == null) && (announcements.DataSource == null)) 
//            {
//                noThreadsToDisplay.Visible = true;
//            } 
//            else 
//            {
//                noThreadsToDisplay.Visible = false;
//            }
//
//
//            pager.TotalRecords = currentPage.TotalRecords = threadSet.TotalRecords;
//            currentPage.TotalPages = pager.CalculateTotalPages();
//            currentPage.PageIndex = pager.PageIndex;
//
//        }
//        #endregion
//
//    }

}